package com.tjn.try_;

/**
 * @author 陶镓妮
 * @version 1.0
 */
public class TryCatchExercise {
    public static int method(){
        int i = 1;
        try{
            i++;//i=2
            String[] names = new String[3];
            if(names[1].equals("tom")){//空指针异常
                System.out.println(names[1]);
            }else{
                names[3] = "tjndy";
            }
            return 1;
        }catch(ArrayIndexOutOfBoundsException e){
            return 2;
        }catch(NullPointerException e){//跳到这里
            return i++;//i=3,保存临时变量temp=3
        }finally{
            ++i;//i=4
            System.out.println("i = " + i);//i=4
        }
    }

    public static void main(String[] args) {
        System.out.println(method());
    }
}
